local minnian = fk.CreateSkill{
  name = "xiaobai__minnian"
}
minnian:addEffect(fk.EnterDying, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(minnian.name) and player:usedSkillTimes(minnian.name, Player.HistoryTurn) == 0
    and player.maxHp ~= #player:getCardIds("h")
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = minnian.name})
  end,

  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 摸牌至体力上限
    local maxHp = player.maxHp
    local handcardNum = #player:getCardIds("h")
    local n = handcardNum - maxHp
    if n > 0 then
      room:askToDiscard(player, {
        min_num = n,
        max_num = n,
        skill_name = minnian.name,
        cancelable = false
      })
    elseif n < 0 then
      player:drawCards(-n, minnian.name)
    end
    if player.dead then return end
    -- 选择横置两名角色
    local ts=table.filter(room.alive_players, function(p)
      return not p.chained
    end)
    if #ts==0 then return end
    local targets = room:askToChoosePlayers(player, {
      targets = ts,
      min_num = 2,
      max_num = 2,
      prompt = "#xiaobai__minnian-choose",
      skill_name = minnian.name,
      cancelable = true
    })
    if player.dead then return end
    if targets then
      for _, p in ipairs(targets) do
        local tar = p
        tar:setChainState(true)
      end
      
      -- 若包含自己则回复1点体力
      if table.contains(targets, player) then
        room:recover({
          who = player,
          num = 1-player.hp,
          recoverBy = player,
          skillName = minnian.name
        })
      end
    end
  end,
})

Fk:loadTranslationTable{
  ["xiaobai__minnian"] = "泯念",
  [":xiaobai__minnian"] = [[每回合限一次，你进入濒死状态时，你可以将手牌调整至体力上限，然后至多横置两名角色，若其中包含你，则你将体力回复至1。]],
  ["#xiaobai__minnian-choose"] = "泯念：选择两名角色，令其横置",

  ["$xiaobai__minnian1"] = "尽子规之血，竭邛赤之水，念念难忘…",
  ["$xiaobai__minnian2"] = "琼田路渺，仙草难寻，岂是寡缘？",
}

return minnian